package com.spzx.product.api.factory;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.dto.OrderStockDTO;
import com.spzx.product.api.domain.query.ProductSkuQuery;
import com.spzx.product.api.domain.vo.ProductSkuVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Component
public class RemoteProductFallbackFactory  implements FallbackFactory<RemoteProductService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductService create(Throwable throwable)
    {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new RemoteProductService()
        {
            @Override
            public R<List<OrderStockDTO>> checkAndLockStock(List<OrderStockDTO> orderStockDTOS) {
                return R.fail("提交订单验库存失败:" + throwable.getMessage());
            }

            @Override
            public R<Map<Long, BigDecimal>> getSkusPrice(List<Long> skuIds) {
                return R.fail("获取订单项价格失败:" + throwable.getMessage());
            }

            @Override
            public R<List<ProductSku>> listIndexSkus() {
                return R.fail("获取热门商品数据失败:" + throwable.getMessage());
            }

            @Override
            public R<Page<ProductSku>> listSkus(ProductSkuQuery query) {
                return R.fail("获取商品列表数据失败:" + throwable.getMessage());
            }

            @Override
            public R<ProductSkuVO> getSkuDetails(Long skuId) {
                return R.fail("获取id="+skuId+" 的商品详情数据失败:" + throwable.getMessage());
            }
        };
    }
}
